package com.hut.oa.controller;

import javax.servlet.http.HttpSession;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hut.oa.common.WebMessage;
import com.hut.oa.common.WebResponse;
import com.hut.oa.common.WebSocketServer;
import com.hut.oa.model.bean.User;

@Controller
@RequestMapping("/socket")
public class WebSocketController {
	
	@RequestMapping("/tongji")
	public String tongji(Model model){
		model.addAttribute("num",WebSocketServer.getOnlineCount());
		model.addAttribute("users",WebSocketServer.getOnlineUsers());
		return "test2";
	}
	
	@RequestMapping("/sendone")
	@ResponseBody
	public String sendMsg(String message,Long userId){
		WebSocketServer.sendMessage(message, userId);
		return "success";
	}
	
	@RequestMapping("/sendall")
	@ResponseBody
	public String sendAll(String message){
		WebSocketServer.sendAll(message);
		return "success";
	}

}
